#ifndef AWX_UDP_H
#define AWX_UDP_H

#include <QWidget>
#include <QUdpSocket>
#include <QNetworkInterface>
#include <QVBoxLayout>
#include <QNetworkDatagram>
#include <awx_udp_parser.h>

namespace Ui {
class AWX_UDP;
}

class AWX_UDP : public QWidget
{
    Q_OBJECT

public:
    explicit AWX_UDP(QWidget *parent = 0);

    ~AWX_UDP();

    void show();

    bool isVaild();

    QNetworkDatagram receiveDatagram(qint64 maxSize = -1);

signals:
    void toggle(bool vaild);

    void readyRead();

private:
    void read_config();

    void write_config();

private slots:
    void on_lineEdit_remote_ip_editingFinished();

    void on_pushButton_connect_clicked();

    void on_socket_stateChanged(QAbstractSocket::SocketState state);

    void show_socket_infomation();

    void on_socket_error(QAbstractSocket::SocketError socketError);

    void on_comboBox_local_ip_currentIndexChanged(const QString &arg1);

    void on_socket_connected();

    void on_socket_disconnected();

    void on_socket_readyRead();

private:
    Ui::AWX_UDP *ui;
    QUdpSocket *socket;
    bool vaild = false;
};

#endif // AWX_UDP_H
